/**
* Created with IntelliJ IDEA.
* Description:
* User: 86187
* Date: 2022-04-16
* Time: 12:03
*/

//Scanner scan = new Scanner(System.in);

//求两数的最大公约数:辗转相除法
import java.util.Scanner;
public class TestNode {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int m = scan.nextInt();
        int c = m;

        while(n % m != 0)
        {
            c = n % m;
            n = m;
            m = c;
        }
        System.out.println(c);
    }

}
